﻿ using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using System.Text;
using System.IO;


namespace zmMoniter
{
    public partial class mainForm : RibbonForm
    {
        public frmLoading frloading = null;
        public frmSetting fmSetting = null;
        private frm2D fr2D = null;
        public  frmDeck2D frDeck2D = null;
        public  treeListEq frEQ = null;
        public  frmHistory frHistory = null;
        private frmNavWarnHistory frNavWarnHistory = null;
        public  frmNavArtifHistory frNavArtifHistory = null;
        private frmWizard frWizard = null;//仓面振捣设计管理
        public  frmReport frReport = null;//报表界面
        private frmWarning frWarning = null;//预警窗口
        private frmUser frUser = null;//用户列表窗口
        private frmAddUser frAddUser = null;//新加用户窗口
        private frmDBSetting fmDBSetting =null;//数据库连接配置 
        private frmServerSetting fmServerSetting = null;//服务器连接配置
        public  frmArtificialUserList fmArtificialUserList = null;//人工振捣用户管理
        public  frmArtificialUser fmArtificialUser = null;//人工振捣用户添加与编辑窗口
        private frmAbout fmAbout = null;//关于窗口
        private string sModelFlag = "2D";
        private bool bFlash = false;
        private sendNeter sender = null;
        private receiveNeter receiver=null;
        public  string sUserID = "";
        public  string sUserName = "";
        public  string sPsw = "";
        public  string sPrvName = "";
        public  string sPrv = "";
        public  int iMonPort;
        public  static mainForm publicFrom;
        public  Hashtable htWarnDeck;

        public static string connstring = "";
        public static string sIP = "";
        public static string sPort = "";
        public static string mIP = "";
        public static string mPort = "";
        public  mainForm()
        {
            
            frloading = new frmLoading(this);
            mainForm.mPort = "123";
            mainForm.mIP = GetIP();
            if (loadConfig())
            {
                frloading.Show();
            }
            else
            {
                DialogResult result = MessageBox.Show("系统配置文件读取失败！是否进入参数设置页面？", "消息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    frloading.Show();
                }
                else
                {
                    showSetting();
                }  
            }//显示启动页面
            InitializeComponent();
            InitSkinGallery();
            publicFrom = this;
            htWarnDeck = new Hashtable();
        }
        public  void InitSkinGallery()
        {
        }
        protected string GetIP()   //获取本地IP
        {
            System.Net.IPHostEntry ipHost = System.Net.Dns.Resolve(System.Net.Dns.GetHostName());
            System.Net.IPAddress ipAddr = ipHost.AddressList[0];
            return ipAddr.ToString();
        }
        private bool loadConfig()
        {
          
            bool bCon=false;
            try            
            {
                FileStream aFile = new FileStream(Application.StartupPath + "\\config.ini", FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr = new StreamReader(aFile);
                string nextLine;
                while ((nextLine = sr.ReadLine()) != null)
                {
                    if (nextLine.IndexOf("[CONNSTRING]") >= 0)
                    {
                        int iPos = nextLine.IndexOf("[CONNSTRING]");

                        mainForm.connstring = nextLine.Substring(iPos + 13, nextLine.Length - 13);
                    }
                    else if (nextLine.IndexOf("[SIP]") >= 0)
                    {
                        int iPos = nextLine.IndexOf("[SIP]");

                        mainForm.sIP = nextLine.Substring(iPos + 6, nextLine.Length - 6);
                    }
                    else if (nextLine.IndexOf("[SPORT]") >= 0)
                    {
                        int iPos = nextLine.IndexOf("[SPORT]");
                        mainForm.sPort = nextLine.Substring(iPos + 8, nextLine.Length - 8);
                    }
                }
                sr.Close();
                if (mainForm.connstring != "" && mainForm.sIP != "" && mainForm.sPort!="")
                    bCon = true;
            }            
            catch (IOException ex)            
            {
                bCon = false;
            }
            return bCon;
        
        }
        //显示主页面
        private void maintimer_Tick(object sender, EventArgs e)
        {
            frloading.Dispose();                                  //关闭SplashScreen
            startTimer(false);                         //关闭maintimer
            this.WindowState = FormWindowState.Maximized;      //打开主界面
            this.ShowInTaskbar = true;
            startWork();
        }
        private void graphtimer_Tick(object sender, EventArgs e)
        {
            upDateGraph();
        }
        private void flashtimer_Tick(object sender, EventArgs e)
        {
            bFlash = !bFlash;
            if (sModelFlag == "2D")
            {
                fr2D.FlashWarning(bFlash);
            }
            else if (sModelFlag == "Deck2D")
            {
                frDeck2D.FlashWarning(bFlash);
                
            }
           

           
        }
        public  void upDateGraph()
        {
            fr2D.loadDamData();
            if (frDeck2D != null && frDeck2D.Visible==true)
            {
                frDeck2D.upDateLayer();
            }
        }
        public  void upDateWarn(bool bUpDate=true)
        {

            startFlashTimer(bUpDate);
            if (bUpDate == false)
            {
                if (sModelFlag == "2D")
                {
                    fr2D.FlashWarning(false);
                }
                else if (sModelFlag == "Deck2D")
                {
                    frDeck2D.FlashWarning(false);
                }
            }
        }
        public  void upDateCaption()
        {
            this.iUser.Caption = string.Format("当前用户:{0}", this.sUserName);
        }
        public  void startTimer(bool bStart)
        {
           this.maintimer.Enabled = bStart;
        }
        public  void startGraphTimer(bool bStart)
        {
            this.graphtimer.Enabled = bStart;
        }
        public  void startFlashTimer(bool bStart)
        {
            this.flashtimer.Enabled = bStart;
        }
        private void mainForm_Load(object sender, EventArgs e)
        {
          
        }
        private void startWork()
        {

            //////////////////////lg-add////////////////////////////////////////////////////
            
            receiver = new receiveNeter(mainForm.sIP,int.Parse(mainForm.sPort), this);//modify by lance 2013.1.22
            //////////////////////lg-add////////////////////////////////////////////////////

            //if (receiveMessage())
            //    siInfo.Caption = "已建监控连接!";
            //else
            //    siInfo.Caption = "监控连接创建异常!";

            if (frEQ == null || frEQ.IsDisposed)
            {
                frEQ = new treeListEq(this);
                frEQ.DockToForm(this.dockManager, DevExpress.XtraBars.Docking.DockingStyle.Left);
                frEQ.selfPanel.TabsPosition = DevExpress.XtraBars.Docking.TabsPosition.Right;
                frEQ.Text = "施工仓面列表";
                frEQ.Show();
            }
            else
            {
                frEQ.Show2(this.dockManager);
            }
            fr2D = new frm2D(this);
            //fr2D.Parent = this;
            fr2D.MdiParent = this;
            fr2D.Dock = DockStyle.Fill;
            fr2D.Show();
            fr2D.loadDamData();
            startGraphTimer(true);
            showWarning();
            creatReport();
        }
        #region **************工具栏按钮响应**************
        private void Invoke_DeckItemClick(object sender, ItemClickEventArgs e)
        {
            switch (e.Item.Caption)
            {
                case "放大":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frDeck2D.setMapMode(1);
                    }
                    break;
                case "缩小":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frDeck2D.setMapMode(2);
                    }
                    break;
                case "拖动":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frDeck2D.setMapMode(3);
                    }
                    break;
                case "全图":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frDeck2D.reDraw();
                    }
                    break;
                case "点选":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frDeck2D.setMapMode(4);
                    }
                    break;
                case "非振捣区域":
                    if (frDeck2D != null && frDeck2D.Visible == true)
                    {
                        frmManger("Deck2D");
                        frDeck2D.clearPlgPoints();
                        frDeck2D.setMapMode(5);
                    }
                    break;
                default:
                    break;
            }
        }
        private void Invoke_ItemClick(object sender, ItemClickEventArgs e)
        {
            switch (e.Item.Caption)
            {
                case "坝块剖面":
                    frmManger("2D");
                    break;
                case "振捣机监控":
                    frmManger("Deck2D");
                    break;
                case "人工振捣监控":
                    break;
                case "仓面振捣设计管理":
                    frmManger("Wizard");
                    break;
                case "开仓":
                    openDeck();
                    break;
                case "关仓":
                    closeDeck();
                    break;
                case "振捣覆盖":
                    frmManger("OverLay");
                    break;
                case "振捣深度":
                    frmManger("Depth");
                    break;
                case "振捣时间":
                    frmManger("Time");
                    break;
                case "有效振捣":
                    frmManger("Qualified");
                    break;
                case "输出图形报表":
                    exportImage();
                    break;
                case "用户列表":
                    showUser();
                    break;
                case "新加用户":
                    addUser();
                    break;
                case "报警记录":
                    frmManger("Warning");
                    break;
                case "消息通知":
                    frmManger("Message");
                    break;
                case "人工振捣":
                    frmManger("Artificial");
                    break;
                case "数据库连接":
                    showDbSertting();
                    break;
                case "服务器连接":
                    showServerSertting();
                    break;
                case "人工振捣用户":
                    frmManger("ArtificialUser");
                    
                    break;
                case "关于我们":
                    frmManger("About");
                    
                    break;
                    
                default:
                    break;
            }
        }
        private void Invoke_DeviceItemClick(object sender, ItemClickEventArgs e)
        {
            switch (e.Item.Caption)
            {
                case "保存设备调度":
                    this.frEQ.saveDevice();
                    break;
                case "重置设备调度":
                    this.frEQ.reSetDevice();
                    break;
                default:
                    break;
            }
        }
        #endregion
        public  void frmManger(string sFlag)
        {
            sModelFlag = sFlag;
            #region **************frm2D显示**************
            if (sFlag == "2D")
            {
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (frHistory != null)
                    frHistory.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                fr2D.Show();
                fr2D.loadDamData();//modify by lance 2013-1-20
                barBtn_Output.Enabled = false;
                rbnPageGroup_Graph.Visible = false;
                barBtn_DrawDeckPlg.Enabled = false;
                rbnPageGroup_quality.Visible = false;
                frEQ.Show2(this.dockManager);
                
            }
            #endregion 
            #region **************frmDeck2D显示**************
            else if(sFlag == "Deck2D")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (frHistory != null)
                    frHistory.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                if (frDeck2D == null)
                {
                    frDeck2D = new frmDeck2D(this);
                    //frDeck2D.Parent = this;
                    frDeck2D.MdiParent = this;
                    frDeck2D.Dock = DockStyle.Fill;
                }
                frDeck2D.Show();
                frDeck2D.upDateLayer();//modify by lance 2013-1-20
                rbnPageGroup_quality.Visible = true;
                rbnPageGroup_Graph.Visible = true;
                barBtn_DrawDeckPlg.Enabled = true;
                frEQ.Show2(this.dockManager);
            }
            #endregion
            #region **************frmWizard显示**************
            else if (sFlag == "Wizard")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (frHistory != null)
                    frHistory.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                if (frWizard == null)
                {
                    frWizard = new frmWizard(this);
                    //frWizard.Parent = this;
                    frWizard.MdiParent = this;
                    frWizard.Dock = DockStyle.Fill;
                }
                frWizard.Show();
                frWizard.reFushData();//modify by lance 2013-1-20
                barBtn_Output.Enabled = false;
                rbnPageGroup_Graph.Visible = false;
                barBtn_DrawDeckPlg.Enabled = false;
                rbnPageGroup_quality.Visible = false;
                frEQ.Show2(this.dockManager);
            }
            #endregion
            #region **************frmReport显示**************
            else if (sFlag == "OverLay" || sFlag == "Depth" || sFlag == "Time" || sFlag == "Qualified")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frHistory != null)
                    frHistory.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                if (frReport == null)
                {
                    frReport = new frmReport(this);
                    //frReport.Parent = this;
                    frReport.MdiParent = this;
                    frReport.Dock = DockStyle.Fill;
                }
                rbnPageGroup_quality.Visible = true;
                rbnPageGroup_Graph.Visible = true;
                barBtn_DrawDeckPlg.Enabled = true;
                frReport.Show();
                frReport.loadLayerData(frDeck2D.sDeckID, frDeck2D.sLayerID, sFlag);
                frEQ.Show2(this.dockManager);
            }
                #endregion 
            #region **************frmHistory显示**************
            else if (sFlag == "Warning")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                if (frNavWarnHistory == null || frNavWarnHistory.IsDisposed)
                {
                    frNavWarnHistory = new frmNavWarnHistory(this);
                    frNavWarnHistory.DockToForm(this.dockManager, DevExpress.XtraBars.Docking.DockingStyle.Left);
                    frNavWarnHistory.selfPanel.TabsPosition = DevExpress.XtraBars.Docking.TabsPosition.Left;
                    frNavWarnHistory.Text = "报警历史记录";
                    frNavWarnHistory.Show();
                }
                else
                {
                    frNavWarnHistory.Show2(this.dockManager);
                }
                if (frHistory == null)
                {
                    frHistory = new frmHistory();
                    frHistory.MdiParent = this;
                    frHistory.Dock = DockStyle.Fill;
                }
                frHistory.setFlag(sFlag);
                frHistory.Show();
            }
            #endregion 
            #region **************frmHistory显示**************
            else if ( sFlag == "Artificial")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (fmArtificialUserList != null)
                    fmArtificialUserList.Hide();
                if (frNavArtifHistory == null || frNavArtifHistory.IsDisposed)
                {
                    frNavArtifHistory = new frmNavArtifHistory(this);
                    frNavArtifHistory.DockToForm(this.dockManager, DevExpress.XtraBars.Docking.DockingStyle.Left);
                    frNavArtifHistory.selfPanel.TabsPosition = DevExpress.XtraBars.Docking.TabsPosition.Left;
                    frNavArtifHistory.Text = "人工振捣监控记录";
                    frNavArtifHistory.Show();
                }
                else
                {
                    frNavArtifHistory.Show2(this.dockManager);
                }
                if (frHistory == null)
                {
                    frHistory = new frmHistory();
                    frHistory.MdiParent = this;
                    frHistory.Dock = DockStyle.Fill;
                }
                frHistory.setFlag(sFlag);
                frHistory.Show();
            }
            #endregion 
            #region **************frmArtificialUserList显示**************
            else if (sFlag == "ArtificialUser")
            {
                if (fr2D != null)
                    fr2D.Hide();
                if (frDeck2D != null)
                    frDeck2D.Hide();
                if (frWizard != null)
                    frWizard.Hide();
                if (frReport != null)
                    frReport.Hide();
                if (frHistory != null)
                    frHistory.Hide();
                if (fmArtificialUserList == null || fmArtificialUserList.IsDisposed)
                {
                    fmArtificialUserList = new frmArtificialUserList(this);

                    fmArtificialUserList.MdiParent = this;
                    fmArtificialUserList.Dock = DockStyle.Fill;

                   
                }
                fmArtificialUserList.Show();
                barBtn_Output.Enabled = false;
                rbnPageGroup_Graph.Visible = false;
                barBtn_DrawDeckPlg.Enabled = false;
                rbnPageGroup_quality.Visible = false;
                
            }
            #endregion 
            #region **************frmAbout显示**************
            else if (sFlag == "About")
            {

                if (fmAbout == null || fmAbout.IsDisposed)
                {
                    fmAbout = new frmAbout();
                }
                fmAbout.TopLevel = true;
                fmAbout.Show();
            }

            #endregion 
            
        }
        
        public void showArtificialUser(bool bFlag,int iCode=-1,string sRFID="", 
            string sName="", string sPos="", string sTel="", string sDepart="")
        {
            if (fmArtificialUser == null)
                fmArtificialUser = new frmArtificialUser(this);
            fmArtificialUser.setUpdateID(iCode);
            if (iCode != -1)
            {
                fmArtificialUser.setModel(false);
                fmArtificialUser.setData(sRFID, sName, sTel, sPos, sDepart);
            }
            else
                fmArtificialUser.setModel(true);
            clearWindow();
            fmArtificialUser.ShowDialog();
        }
        public void creatReport()
        {
            if (frReport == null)
            {
                frReport = new frmReport(this);
                frReport.MdiParent = this;
                frReport.Dock = DockStyle.Fill;
            }
        }
        public  void showLayer2d(string sVID,string sID)
        {
            frmManger("Deck2D");
            frDeck2D.loadLayerData(sVID, sID);

        }
        public  void showDeck2d(string sdID)
        {
            frmManger("Deck2D");
            frDeck2D.loadDeckData(sdID);
        }
        public  void setDeckState(int ideckID,int iState)
        {
            if (iState==1)//已经开启的
            {
                barbtn_OpanDeck.Enabled = false;
                barbtn_OpanDeck.Tag = (object)ideckID;
                barBtn_CloseDeck.Enabled = true;
                barBtn_CloseDeck.Tag = (object)ideckID;
            }
            else if (iState==2)//规划的
            {
                barbtn_OpanDeck.Enabled = true;
                barbtn_OpanDeck.Tag = (object)ideckID;
                barBtn_CloseDeck.Enabled = false;
                barBtn_CloseDeck.Tag = (object)ideckID;
            }
            else if (iState == 0)//关仓的
            {
                barbtn_OpanDeck.Enabled = true;
                barbtn_OpanDeck.Tag = (object)ideckID;
                barBtn_CloseDeck.Enabled = false;
                barBtn_CloseDeck.Tag = (object)ideckID;
            }
            else //仓完成的
            {
                barbtn_OpanDeck.Enabled = false;
                barbtn_OpanDeck.Tag = (object)ideckID;
                barBtn_CloseDeck.Enabled = false;
                barBtn_CloseDeck.Tag = (object)ideckID;
            }
        }
        public  void openDeck()
        {
            int ideckID = (int)barbtn_OpanDeck.Tag;
            OpenDeck opnDeck = new OpenDeck(this, ideckID);
            pgsPanel.Caption = "正在进行开仓操作...";
            pgsPanel.Description = "";
            pgsPanel.SetBounds(this.Width / 2 - 100, this.Height / 2 - 40, 200, 80);
            pgsPanel.Visible = true;
            opnDeck.open();
        }
        public  void closeDeck()
        {
            int ideckID = (int)barBtn_CloseDeck.Tag;
            CloseDeck clsDeck = new CloseDeck(this, ideckID);
            pgsPanel.Caption = "正在进行关仓操作...";
            pgsPanel.Description = "";
            pgsPanel.SetBounds(this.Width / 2 - 100, this.Height / 2 - 40, 200, 80);
            pgsPanel.Visible = true;
            clsDeck.comput();
        }
        /// <summary>
        /// 获取规划设备
        /// </summary>
        /// <param name="cmCode">仓面号</param>
        public  string getPlanDevice(int cmCode)
        {
            string sSQL = @"SELECT   规划设备 FROM  仓面信息 where 编号=" + cmCode;
            PublicDataCls db = new PublicDataCls();
            db.OpenConn();
            DataTable dt = db.ReturnDataTable(sSQL);
            if (dt == null || dt.Rows.Count == 0)
                return "";
            else
                return dt.Rows[0][0].ToString();
        }

        private void exportImage()
        {
            frReport.exportImg();
        }
        private void showUser()
        {
            if (frUser == null)
                frUser = new frmUser(this);
            clearWindow();
            frUser.Owner = this;
            frUser.ShowDialog();
        }
        private void addUser()
        {
            if (frAddUser == null)
                frAddUser = new frmAddUser(this);
            clearWindow();
            frAddUser.Owner = this;
            frAddUser.ShowDialog();
        }
        public void clearWindow()
        {
            if (fmAbout != null && fmAbout.Visible == true)
                fmAbout.Hide();
        }
        public  void seedMessage(string sMSG)
        {
            if (sMSG == null)
                return;
          
            sender = new sendNeter(mainForm.sIP,int.Parse(mainForm.sPort));//modify by lance 2013.1.22
            sender.seedMessage(sMSG);
        }
        public  bool receiveMessage()
        {
            bool bResult = false;
            try
            {
                if (receiver == null)
                {

                    receiver = new receiveNeter(mainForm.sIP, int.Parse(mainForm.sPort), this);//modify by lance 2013.1.22
                    
                }
                bResult = true;
            }
            catch (Exception e)
            {
                bResult = false;
            }
            return bResult;
            
        }
        public  void setNeterParameter(string sIP, int sPort, string mIP, int mPort)
        {
         
            mainForm.sPort=sPort.ToString();
            mainForm.sIP = sIP;
          
        }
        public  void upDateXYInfo(double dx, double dy)
        {
            barBItem_XY.Caption = "x=" + dx.ToString("F2") + ",y=" + dy.ToString("F2");
        }
        
           
        public  bool showWarning()
        {
            bool bResult = false;
            if (frWarning == null)
            {
                frWarning = new frmWarning(this);
                frWarning.warningTimer.Enabled = true;
            }
            if (frWarning.reLoadData(true))
            {
                frWarning.Owner = this;
                hideOrtherWind();
                frWarning.ShowDialog();
            }
            else
            {
                frWarning.Hide();
            }
            return bResult;
        }
        public  bool showWarning(string sDeckID, string sGUIDs)
        {
            bool bResult = false;
            if (frWarning == null)
            {
                frWarning = new frmWarning(this);
                frWarning.warningTimer.Enabled = true;
            }
            if (frWarning.loadDate(sDeckID, sGUIDs))
            {
                frWarning.Owner = this;
                hideOrtherWind();
                frWarning.ShowDialog();
            }
            else
            {
                frWarning.Hide();
            }
            return bResult;
        }
        public  void hideOrtherWind()
        {
            if(frUser!= null)
                frUser.Hide();
            if(frAddUser!= null)
                frAddUser.Hide();
            if (fmDBSetting != null)
                fmDBSetting.Hide();
            if (fmServerSetting != null)
                fmServerSetting.Hide();
        }
        public  void setDateByBlock(string setDateByBlock)
        {
             frEQ.setDateByBlock(setDateByBlock);
        }
        public  void setDateByLayer(string sDeckName,string sDeckID, string sLayerID)
        {
            frmManger("Deck2D");
            frEQ.setDateByLayer(sDeckName,sDeckID, sLayerID);

        }
        private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.ApplicationExitCall)
                return;  
            DialogResult result = MessageBox.Show("是否退出系统?", "消息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }
            else
            {
                e.Cancel = false;
                frloading.Logout();
                Application.Exit();
            }  
        }
        public  void setPurview(bool bTrue)
        {
            if (bTrue)
            {
                rbnPageGroup_eqManager.Visible = true;
                ribbonPg_User.Visible = true;
            }
            else
            {
                rbnPageGroup_eqManager.Visible = false;
                ribbonPg_User.Visible = false;
                btn_Select.Enabled = false;
            }
        }
        public  void clearWarning()
        {
            foreach (DictionaryEntry de in htWarnDeck)
            {
                Hashtable htWarning = (Hashtable)de.Value;
                foreach (DictionaryEntry subde in htWarning)
                {
                    ArrayList alWarning = (ArrayList)subde.Value;
                    alWarning.Clear();
                }
            }
        }
        
        public  void showDbSertting(int iMode=0)
        {
           if(fmDBSetting==null)
              fmDBSetting = new frmDBSetting(this);
           clearWindow();
           
           fmDBSetting.reSetData();
           fmDBSetting.ShowDialog();
           
        }
        public  void showServerSertting()
        {
            if(fmServerSetting==null)
               fmServerSetting = new frmServerSetting(this);
            clearWindow();
            fmServerSetting.reSetData();
            fmServerSetting.ShowDialog();

        }
        public void showSetting()
        {
            if (fmSetting == null)
                fmSetting = new frmSetting(this);
            fmSetting.reSetData();
            fmSetting.ShowDialog();

        }
        private void dockManager_ActivePanelChanged(object sender, DevExpress.XtraBars.Docking.ActivePanelChangedEventArgs e)
        {
            if (e.Panel == null)
                return;
            if (e.Panel.Text == "人工振捣监控记录")
            {
                frHistory.setFlag("Artificial");
                frmManger("Artificial");
            }
            else if (e.Panel.Text == "报警历史记录")
            {
                frHistory.setFlag("Warning");
                frmManger("Warning");
            }
            
        }
    }
}